<extend name="Common@Layout:layui-admin" />
<block name="title">
    <title>还原数据库-Administator管理后台</title>
</block>
<block name="style">
    <style>
        body {
            padding: 10px;
        }
    </style>
</block>

<block name="main">

    <!-- 应用列表 -->
    <div class="dataTables_wrapper no-footer">
        <table class="layui-table layui-form dataTable no-footer" role="grid">
            <thead>
                <tr>
                    <th style="width:200px !important;">备份名称</th>
                    <th width="80">卷数</th>
                    <th width="80">压缩</th>
                    <th width="80">数据大小</th>
                    <th width="200">备份时间</th>
                    <th width="80">状态</th>
                    <th width="120">操作</th>
                </tr>
            </thead>
            <tbody>
                <volist name="list" id="data">
                    <tr>
                        <td>{$data.time|date='Ymd-His',###}</td>
                        <td>{$data.part}</td>
                        <td>{$data.compress}</td>
                        <td>{$data.size|format_bytes}</td>
                        <td>{$key}</td>
                        <td>-</td>
                        <td class="action">
                            <if condition="$_GET['import'] eq 1"><a class="layui-btn layui-btn-small db-import" href="{:U('import?time='.$data['time'])}">还原</a>&nbsp;</if>
                            <a class="layui-btn layui-btn-small mini_del" href="javascript:;" data-url="{:U('del?time='.$data['time'])}">删除</a>
                        </td>
                    </tr>
                </volist>
            </tbody>
        </table>
    </div>
    <!-- /应用列表 -->
</block>

<block name="script">
    <script type="text/javascript">
        layui.use(['jquery'], function() {

            var $ = layui.jquery,
                jquery = layui.jquery;

            $(".db-import").click(function() {
                var self = this,
                    status = ".";
                $.get(self.href, success, "json");
                window.onbeforeunload = function() {
                    return "正在还原数据库，请不要关闭！"
                }
                return false;

                function success(data) {
                    if (data.status) {
                        if (data.gz) {
                            data.info += status;
                            if (status.length === 5) {
                                status = ".";
                            } else {
                                status += ".";
                            }
                        }
                        $(self).parent().prev().text(data.info);
                        if (data.part) {
                            $.get(self.href, {
                                    "part": data.part,
                                    "start": data.start
                                },
                                success,
                                "json"
                            );
                        } else {
                            window.onbeforeunload = function() {
                                return null;
                            }
                        }
                    } else {
                        updateAlert(data.info, 'alert-error');
                    }
                }
            });

            function updateAlert(info, type) {
                if (type == 'alert-success') {
                    layer.msg(info, {
                        icon: 1,
                        time: 1000
                    });
                } else {
                    layer.msg(info, {
                        icon: 2,
                        time: 1000
                    });
                }
            }
        });
    </script>
</block>